<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initView() {

        $view = new Zend_View();
        $view->doctype('XHTML1_STRICT');
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
                ->appendHttpEquiv('Content-Language', 'pl-PL');
        $view->headTitle()->setSeparator(' ');

        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setView($view);

        $this->bootstrap('layout');

        Zend_Layout::startMvc();
        $layout = Zend_Layout::getMvcInstance();
        
        return $view;
    }

    protected function _initRewrite() {

        $front = Zend_Controller_Front::getInstance();
        $router = $front->getRouter();
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'production');
        $configStatis = new Zend_Config_Ini(APPLICATION_PATH . '/configs/staticroutes.ini');

        $router->addConfig($config, 'routes');
        if ($configStatis->routes)
            $router->addConfig($configStatis, 'routes');
    }

    protected function _initRegistry() {

        Zend_Registry::set('config', new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV));
        Zend_Registry::set('staticSalt', Zend_Registry::get('config')->staticSalt);
    }

    protected function _initMail() {

        $this->bootstrap('registry');
        $mr = $this->getPluginResource('mail');
        $options = $mr->getOptions();
        Zend_Registry::set('mail', $options);
        $transport = new Zend_Mail_Transport_Smtp($options['transport']['host'], $options['transport']);
        Zend_Mail::setDefaultTransport($transport);
    }

    protected function _initLogger() {

        $this->bootstrap(array('registry'));

        $logger = Zend_Log::factory(array(
                    'timestampFormat' => 'Y-m-d H:i:s',
                    array(
                        'writerName' => 'Stream',
                        'writerParams' => array(
                            'stream' => APPLICATION_PATH . '/tmp/log/main.log',
                        ),
                        'formatterName' => 'Simple',
                        'formatterParams' => array(
                            'format' => '%timestamp%: %message% -- %info%' . "" . PHP_EOL,
                        ),
                        'filterName' => 'Priority',
                        'filterParams' => array(
                            'priority' => Zend_Log::WARN,
                        ),
                    ),
                    array(
                        'writerName' => 'Firebug',
                        'filterName' => 'Priority',
                        'filterParams' => array(
                            'priority' => Zend_Log::INFO,
                        ),
                    ),
                ));

        Zend_Registry::set("logger", $logger);
    }

}

